<?php

namespace Acme\UserBundle\Entity;

use Acme\PersonBundle\Entity\Person;
use Acme\EventBundle\Entity\Information;
use Acme\EventBundle\Entity\Inscription;
use Acme\EventBundle\Entity\Feedback;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;

/**
 * Acme\UserBundle\Entity\User
 *
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 */
class User implements AdvancedUserInterface, \Serializable {
	
	/**
	 * @ORM\Column(type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	private $id;
	
	/**
	 * @ORM\Column(type="string", length=25, unique=true)
	 */
	private $username;
	
	/**
	 * @ORM\Column(type="string", length=32)
	 */
	private $salt;
	
	/**
	 * @ORM\Column(type="string", length=64)
	 */
	private $password;
	
	/**
	 * @ORM\Column(type="string", length=60, unique=true)
	 */
	private $email;
	
	/**
	 * @ORM\Column(name="is_active", type="boolean")
	 */
	private $isActive;
	
	/**
	 * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
	 */
	protected $roles;
	
	/**
	 * @ORM\ManyToMany(targetEntity="\Acme\PersonBundle\Entity\Person", inversedBy="users")
	 */
	protected $persons;
	
	/**
	 * @ORM\ManyToMany(targetEntity="\Acme\PinnwandBundle\Entity\Pinnwand", inversedBy="users")
	 */
	protected $pinnwands;
	
	/**
	 * @ORM\OneToMany(targetEntity="\Acme\EventBundle\Entity\Inscription", mappedBy="user")
	 */
	protected $inscriptions;
	
	/**
	 * @ORM\OneToMany(targetEntity="\Acme\EventBundle\Entity\Information", mappedBy="user")
	 */
	protected $informations;
	
	/**
	 * @ORM\Column(name="lastActivity", type="datetime")
	 */
	protected $lastActivity;
	public function __construct() {
		$this->roles = new \Doctrine\Common\Collections\ArrayCollection ();
		$this->persons = new \Doctrine\Common\Collections\ArrayCollection ();
		$this->pinnwands = new \Doctrine\Common\Collections\ArrayCollection ();
	}
	
	/**
	 * Get id
	 *
	 * @return integer
	 */
	public function getId() {
		return $this->id;
	}
	
	/**
	 * Set username
	 *
	 * @param string $username        	
	 * @return User
	 */
	public function setUsername($username) {
		$this->username = $username;
		
		return $this;
	}
	
	/**
	 * Get username
	 *
	 * @return string
	 */
	public function getUsername() {
		return $this->username;
	}
	
	/**
	 * Set salt
	 *
	 * @param string $salt        	
	 * @return User
	 */
	public function setSalt($salt) {
		$this->salt = $salt;
		
		return $this;
	}
	
	/**
	 * Get salt
	 *
	 * @return string
	 */
	public function getSalt() {
		return $this->salt;
	}
	
	/**
	 * Set password
	 *
	 * @param string $password        	
	 * @return User
	 */
	public function setPassword($password) {
		$this->password = $password;
		
		return $this;
	}
	
	/**
	 * Get password
	 *
	 * @return string
	 */
	public function getPassword() {
		return $this->password;
	}
	
	/**
	 * Set email
	 *
	 * @param string $email        	
	 * @return User
	 */
	public function setEmail($email) {
		$this->email = $email;
		
		return $this;
	}
	
	/**
	 * Get email
	 *
	 * @return string
	 */
	public function getEmail() {
		return $this->email;
	}
	
	/**
	 * Set isActive
	 *
	 * @param boolean $isActive        	
	 * @return User
	 */
	public function setIsActive($isActive) {
		$this->isActive = $isActive;
		
		return $this;
	}
	
	/**
	 * Get isActive
	 *
	 * @return boolean
	 */
	public function getIsActive() {
		return $this->isActive;
	}
	
	/**
	 * @inheritDoc
	 */
	public function getRoles() {
		return $this->roles->toArray ();
	}
	
	/**
	 * @inheritDoc
	 */
	public function eraseCredentials() {
	}
	
	/**
	 *
	 * @see \Serializable::serialize()
	 */
	public function serialize() {
		return serialize ( array (
				$this->id 
		) );
	}
	
	/**
	 *
	 * @see \Serializable::unserialize()
	 */
	public function unserialize($serialized) {
		list ( $this->id, ) = unserialize ( $serialized );
	}
	public function isAccountNonExpired() {
		return true;
	}
	public function isAccountNonLocked() {
		return true;
	}
	public function isCredentialsNonExpired() {
		return true;
	}
	public function isEnabled() {
		return $this->isActive;
	}
	
	/**
	 * Add roles
	 *
	 * @param \Acme\UserBundle\Entity\Role $roles        	
	 * @return User
	 */
	public function addRole(\Acme\UserBundle\Entity\Role $roles) {
		$this->roles [] = $roles;
		
		return $this;
	}
	
	/**
	 * Remove roles
	 *
	 * @param \Acme\UserBundle\Entity\Role $roles        	
	 */
	public function removeRole(\Acme\UserBundle\Entity\Role $roles) {
		$this->roles->removeElement ( $roles );
	}
	
	/**
	 * Add persons
	 *
	 * @param \Acme\PersonBundle\Entity\Person $persons        	
	 * @return User
	 */
	public function addPerson(\Acme\PersonBundle\Entity\Person $persons) {
		$this->persons [] = $persons;
		
		return $this;
	}
	
	/**
	 * Remove persons
	 *
	 * @param \Acme\PersonBundle\Entity\Person $persons        	
	 */
	public function removePerson(\Acme\PersonBundle\Entity\Person $persons) {
		$this->persons->removeElement ( $persons );
	}
	
	/**
	 * Get persons
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getPersons() {
		return $this->persons;
	}
	
	/**
	 * Add pinnwands
	 *
	 * @param \Acme\PinnwandBundle\Entity\Pinnwand $pinnwands        	
	 * @return User
	 */
	public function addPinnwand(\Acme\PinnwandBundle\Entity\Pinnwand $pinnwands) {
		$this->pinnwands [] = $pinnwands;
		
		return $this;
	}
	
	/**
	 * Remove pinnwands
	 *
	 * @param \Acme\PinnwandBundle\Entity\Pinnwand $pinnwands        	
	 */
	public function removePinnwand(\Acme\PinnwandBundle\Entity\Pinnwand $pinnwands) {
		$this->pinnwands->removeElement ( $pinnwands );
	}
	
	/**
	 * Get pinnwands
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getPinnwands() {
		return $this->pinnwands;
	}
	
	/**
	 * Set lastActivity
	 *
	 * @param \DateTime $lastActivity        	
	 * @return User
	 */
	public function setLastActivity($dateTime = '') {
		if ($dateTime != '') {
			$format = new \DateTime ( $dateTime );
			$this->lastActivity = $format;
		} else {
			$this->lastActivity = new \DateTime ();
		}
		
		return $this;
	}
	public function isActiveNow() {
		$this->setLastActivity ();
	}
	
	/**
	 * Get lastActivity
	 *
	 * @return \DateTime
	 */
	public function getLastActivity() {
		return $this->lastActivity;
	}
	
	/**
	 * Add inscriptions
	 *
	 * @param \Acme\EventBundle\Entity\Inscription $inscriptions        	
	 * @return User
	 */
	public function addInscription(\Acme\EventBundle\Entity\Inscription $inscriptions) {
		$this->inscriptions [] = $inscriptions;
		
		return $this;
	}
	
	/**
	 * Remove inscriptions
	 *
	 * @param \Acme\EventBundle\Entity\Inscription $inscriptions        	
	 */
	public function removeInscription(\Acme\EventBundle\Entity\Inscription $inscriptions) {
		$this->inscriptions->removeElement ( $inscriptions );
	}
	
	/**
	 * Get inscriptions
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getInscriptions() {
		return $this->inscriptions;
	}
	
	/**
	 * Add informations
	 *
	 * @param \Acme\EventBundle\Entity\Information $informations        	
	 * @return User
	 */
	public function addInformation(\Acme\EventBundle\Entity\Information $informations) {
		$this->informations [] = $informations;
		
		return $this;
	}
	
	/**
	 * Remove informations
	 *
	 * @param \Acme\EventBundle\Entity\Information $informations        	
	 */
	public function removeInformation(\Acme\EventBundle\Entity\Information $informations) {
		$this->informations->removeElement ( $informations );
	}
	
	/**
	 * Get informations
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getInformations() {
		return $this->informations;
	}
	public function __toString() {
		return ( string ) $this->persons [0]->getLastname ();
	}
}